package Test;

import Data.SendingMessage;
import Data.User;
import junit.framework.TestCase;
import Context.Constant;

public class DataTest extends TestCase {
	public void testUser() {
		User user1 = new User();
		
		user1.setGroup("msHome");
		user1.setHost("localhost");
		user1.setIp("127.0.0.1");
		user1.setUserName("Sean Lionheart");
		user1.setUserState(Constant.ONLINE);
		
		assertEquals("msHome",user1.getGroup());
		assertEquals("localhost",user1.getHost());
		assertEquals("127.0.0.1",user1.getIp());
		assertEquals("Sean Lionheart",user1.getUserName());
		assertEquals(Constant.ONLINE,user1.getUserState());
		
		User user2 = new User("Sean Lionheart",
				"127.0.0.1","msHome","localhost",Constant.ONLINE);
		
		assertEquals("msHome",user2.getGroup());
		assertEquals("localhost",user2.getHost());
		assertEquals("127.0.0.1",user2.getIp());
		assertEquals("Sean Lionheart",user2.getUserName());
		assertEquals(Constant.ONLINE,user2.getUserState());
		
	}

	    
	public void testSendingMessage(){
		SendingMessage message1=new SendingMessage("1.0.0",1,"roger",
				"roger-pc",0x00000001,"this is the meesage","192.168.2.10");
		
		assertEquals("1.0.0",message1.getVersion());
		assertEquals(1,message1.getPacketNo());
		assertEquals("roger",message1.getSenderName());
		assertEquals("roger-pc",message1.getHostIP());
		assertEquals(0x00000001,message1.getFlag());
		assertEquals("this is the meesage",message1.getAdditional());
		assertEquals("192.168.2.10",message1.getGuestIp());
		
		SendingMessage message2 = new SendingMessage();
		message2.setVersion("1.0.0");
		message2.setPacketNo(1);
		message2.setSenderName("roger");
		message2.setHostIP("roger-pc");
		message2.setFlag(1);
		message2.setAdditional("this is the meesage");
		message2.setGuestIp("192.168.2.10");
		
		assertEquals("1.0.0",message2.getVersion());
		assertEquals(1,message2.getPacketNo());
		assertEquals("roger",message2.getSenderName());
		assertEquals("roger-pc",message2.getHostIP());
		assertEquals(0x00000001,message2.getFlag());
		assertEquals("this is the meesage",message2.getAdditional());
		assertEquals("192.168.2.10",message2.getGuestIp());
		
		message2.setPacketNo("2");
		message2.setFlag("2");
		
		assertEquals(2,message2.getPacketNo());
		assertEquals(0x00000002,message2.getFlag());
		
		SendingMessage message3 = new SendingMessage(message1.toBuffer()
				,"192.168.2.10");
		
		assertEquals("1.0.0",message3.getVersion());
		assertEquals(1,message3.getPacketNo());
		assertEquals("roger",message3.getSenderName());
		assertEquals("roger-pc",message3.getHostIP());
		assertEquals(0x00000001,message3.getFlag());
		assertEquals("this is the meesage",message3.getAdditional());
		assertEquals("192.168.2.10",message3.getGuestIp());
		
		System.out.println("test is over");
	}
}
